package com.xiaoshuidi.cloud.module.bpm.job.delayjob.strategy;

import com.xiaoshuidi.cloud.module.bpm.job.delayjob.TicketDelayJobTypeEnum;
import com.xiaoshuidi.cloud.module.rooms.enums.DelayJobType.DelayJobTypeEnum;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Component
public class ProcessingTask {
    @Resource
    private ReminderOfAcceptanceTimeoutStrategy reminderOfAcceptanceTimeoutStrategy;
    @Resource
    private RepairTimeoutReminderStrategy repairTimeoutReminderStrategy;
    @Resource
    private CompletionTimeoutReminderStrategy completionTimeoutReminderStrategy;


    private static Map<TicketDelayJobTypeEnum, IStrategy> iStrategyMap = new HashMap<TicketDelayJobTypeEnum, IStrategy>();

    @PostConstruct
    public void post() {
        iStrategyMap.put(TicketDelayJobTypeEnum.REMINDER_OF_ACCEPTANCE_TIMEOUT, reminderOfAcceptanceTimeoutStrategy);
        iStrategyMap.put(TicketDelayJobTypeEnum.REPAIR_TIMEOUT_REMINDER, repairTimeoutReminderStrategy);
        iStrategyMap.put(TicketDelayJobTypeEnum.COMPLETION_TIMEOUT_REMINDER, completionTimeoutReminderStrategy);
    }

    public IStrategy getStrategy(TicketDelayJobTypeEnum key) {
        IStrategy iStrategy = iStrategyMap.get(key);
        if (iStrategy == null) {
            throw new RuntimeException("策略有误");
        }
        return iStrategy;
    }
}
